#ifndef USERMGR_H
#define USERMGR_H
#include <QMap>
#include <QObject>
#include <QString>
#include <QVector>
#include "signleton.h"
#include "userdata.h"
#include <memory>
class UserMgr : public QObject,
                public Signleton<UserMgr>,
                public std::enable_shared_from_this<UserMgr>
{
    Q_OBJECT
    friend class Signleton<UserMgr>;

private:
    UserMgr();
    // 用户信息
    std::shared_ptr<UserInfo> _userInfo;
    unsigned int _chat_loaded;
    unsigned int _contact_loaded;
    // 好友申请
    QVector<std::shared_ptr<ApplyInfo>> _applyList;
    // 联系人列表
    QMap<int, std::shared_ptr<FriendInfo>> _friends;
    QVector<std::shared_ptr<FriendInfo>> _friendList;
    // 未收到的好友消息
    QVector<std::shared_ptr<TextChatData>> _unreceived_message_list;

public:
    ~UserMgr();
    int GetUid();
    void SetUserInfo(std::shared_ptr<UserInfo> userInfo);
    std::shared_ptr<UserInfo> GetUserInfo();
    QVector<std::shared_ptr<ApplyInfo>> GetApplyList();
    bool AlreadyApply(int uid);
    void AddApplyList(QJsonArray array);
    void AddApplyInfo(std::shared_ptr<ApplyInfo>);
    void AddFriend(std::shared_ptr<FriendInfo>);
    bool FriendExists(int);
    void AddFriendList(QJsonArray array);
    QVector<std::shared_ptr<FriendInfo>> &GetFriendList();
    // 获取一页聊天列表
    QVector<std::shared_ptr<FriendInfo>> GetChatListPerPage();
    bool IsLoadChatFinish();
    void UpdateChatLoadedCount();
    // 获取一页联系人
    QVector<std::shared_ptr<FriendInfo>> GetContactListPerPage();
    bool IsLoadContactFinish();
    void UpdateContactLoadedCount();
    std::shared_ptr<FriendInfo> GetFriend(int);
    // 添加好友消息
    void AddMessageList(QJsonArray array, QVector<QString> &msg_id_list);
    // 获取未收到的消息
    QVector<std::shared_ptr<TextChatData>> &GetUnreceivedMessageList();
};

#endif // USERMGR_H
